package cn.ffcs.uec.view.component;

import java.io.IOException;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;

import lombok.Getter;
import lombok.Setter;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.zkoss.zk.ui.Components;
import org.zkoss.zk.ui.Executions;
import org.zkoss.zk.ui.IdSpace;
import org.zkoss.zul.Div;
import org.zkoss.zul.Messagebox;

import cn.ffcs.raptornuke.plugin.common.zk.util.ZkUtil;
import cn.ffcs.raptornuke.portal.kernel.xml.DocumentException;
import cn.ffcs.uec.staff.constant.UecStaffConstants;
import cn.ffcs.uec.view.component.bean.LogDownListboxBean;
import cn.ffcs.uec.view.manager.LogDownManager;
import cn.ffcs.uec.view.manager.UecStaffAllManager;
import cn.ffcs.uec.view.model.LogDown;
import cn.ffcs.uec.view.model.UecStaffAll;
import cn.ffcs.uom.common.util.ApplicationContextUtil;
import cn.ffcs.uom.common.util.IPortletInfoProvider;
import cn.ffcs.uom.common.util.ListboxUtils;
import cn.ffcs.uom.common.util.PlatformUtil;
import cn.ffcs.uom.common.util.PubUtil;
import cn.ffcs.uom.common.util.StrUtil;
import cn.ffcs.uom.common.vo.NodeVo;

@Controller
@Scope("prototype")
public class LogDownListboxExt_bak extends Div implements IdSpace {
	protected final Log log = LogFactory.getLog(this.getClass());
	private static final long serialVersionUID = -2212731640371254189L;

	/**
	 * 对应页面上的bean
	 */
	@Getter
	@Setter
	private LogDownListboxBean bean = new LogDownListboxBean();

	/**
	 * 外包人员虚拟对象
	 */
	private UecStaffAll uecStaffAll;
	private String  labelcType = "";
	private String  labelhType = "";
	private String  labelzType = "";
	
	private LogDown logDown;

	private UecStaffAllManager uecStaffAllManager = (UecStaffAllManager) ApplicationContextUtil
			.getBean("uecStaffAllManager");
	
	private LogDownManager logDownManager = (LogDownManager) ApplicationContextUtil
			.getBean("logDownManager");
	

	@Getter
	@Setter
	private IPortletInfoProvider portletInfoProvider;

	public LogDownListboxExt_bak() {
		Executions.createComponents(UecStaffConstants.LOG_DOWN_LISTBOX_ZUL, this, null);
		Components.wireVariables(this, bean);
		Components.addForwards(this, this, '$');
	}
	
	/**
	 * 初始化
	 * 
	 * @throws ParseException
	 * @throws InterruptedException 
	 */
	public void onCreate() throws ParseException, InterruptedException {
		this.bindCombobox();
		this.binbBean();
	}


	/**
	 * 绑定combobox
	 */
	private void bindCombobox() {
		//初始化专业类别
		List<NodeVo> joinCategoryList = new ArrayList<NodeVo>();
			String[][] glbdef10 = { { "营销类", "营销类" }, { "技术类", "技术类" },
					{ "综合类", "综合类" }
					 };
			for (int i = 0; i < glbdef10.length; i++) {
				NodeVo nodeVo = new NodeVo();
				for (int j = 0; j < 1; j++) {
					nodeVo.setId(glbdef10[i][j]);
					nodeVo.setName(glbdef10[i][j + 1]);
				}
				joinCategoryList.add(nodeVo);
			}
			ListboxUtils.rendererForEdit(bean.getTalentname(), joinCategoryList);
			
			/**
			 * 是否组监
			 */
			List<NodeVo> issupervisorList = new ArrayList<NodeVo>();
				String[][] glbdef11 = { { "是", "是" }, { "否", "否" }};
				for (int i = 0; i < glbdef11.length; i++) {
					NodeVo nodeVo = new NodeVo();
					for (int j = 0; j < 1; j++) {
						nodeVo.setId(glbdef11[i][j]);
						nodeVo.setName(glbdef11[i][j + 1]);
					}
					issupervisorList.add(nodeVo);
				}
				ListboxUtils.rendererForEdit(bean.getIssupervisor(), issupervisorList);
			/**
			 * 所有子标签（产品类）	
			 */
				List<NodeVo> talentcLabelList = new ArrayList<NodeVo>();
				String[][] glbdef12 = { { "智能连接", "智能连接" }, { "智慧家庭", "智慧家庭" },
						{ "物联网", "物联网" }, { "互联网金融", "互联网金融" },
						{ "新兴ICT应用", "新兴ICT应用" },{"其他","其他"} };
				for (int i = 0; i < glbdef12.length; i++) {
					NodeVo nodeVo = new NodeVo();
					for (int j = 0; j < 1; j++) {
						nodeVo.setId(glbdef12[i][j]);
						nodeVo.setName(glbdef12[i][j + 1]);
					}
					talentcLabelList.add(nodeVo);
				}
				ListboxUtils.rendererForEdit(bean.getTalentcLabel(), talentcLabelList);
				/**
				  * 行业类
				 */
				List<NodeVo> talenthLabelList = new ArrayList<NodeVo>();
				String[][] glbdef13 = { { "政务", "政务" }, { "军民融合", "军民融合" },
						{ "金融", "金融" }, { "工业企业", "工业企业" },
						{ "互联网", "互联网" },{"商客","商客"},{"教育","教育"},{"现代农业","现代农业"},
						{"交通物流","交通物流"},{"医卫","医卫"},{"其他","其他"}};
				for (int k = 0; k < glbdef13.length; k++) {
					NodeVo nodeVo = new NodeVo();
					for (int j = 0; j < 1; j++) {
						nodeVo.setId(glbdef13[k][j]);
						nodeVo.setName(glbdef13[k][j + 1]);
					}
					talenthLabelList.add(nodeVo);
				}
				ListboxUtils.rendererForEdit(bean.getTalenthLabel(), talenthLabelList);
				/**
				  * 综合类
				 */
			List<NodeVo> talentzLabelList = new ArrayList<NodeVo>();
				String[][] glbdef14 = { { "战力运营", "战力运营" }, { "人力资源", "人力资源" },
						{ "法律", "法律" }, { "财务管理", "财务管理" },
						{ "党群工会", "党群工会" },{ "风险管理", "风险管理" },
						{ "行政后勤", "行政后勤" }};
				for (int i = 0; i < glbdef14.length; i++) {
					NodeVo nodeVo1 = new NodeVo();
					for (int j = 0; j < 1; j++) {
						nodeVo1.setId(glbdef14[i][j]);
						nodeVo1.setName(glbdef14[i][j + 1]);
					}
					talentzLabelList.add(nodeVo1);
				}
				ListboxUtils.rendererForEdit(bean.getTalentzLabel(), talentzLabelList);
			}				
	/**
	 * 监听专业类别，带出子专业、专家等级
	 * @throws ParseException 
	 * @throws com.itextpdf.text.DocumentException 
	 * @throws IOException 
	 * @throws DocumentException 
	 */
	public void onSelect$talentCategory() throws DocumentException, IOException, com.itextpdf.text.DocumentException, ParseException {
		//获取专业类别
		String talentCategory = (String)bean.getTalentname().getSelectedItem().getValue();
		/**
		 * 子专业
		 */
			List<NodeVo> childCategoryList = new ArrayList<NodeVo>();	
		if("营销类".equals(talentCategory)) {
			String[][] glbdef11 = { { "营销综合", "营销综合" }, { "营销策划域拓展", "营销策划域拓展" },
					{ "渠道管理", "渠道管理" }, { "业务管理", "业务管理" },
					{ "生态化产品运营", "生态化产品运营" },{"客户服务","客户服务"} };
			for (int i = 0; i < glbdef11.length; i++) {
				NodeVo nodeVo = new NodeVo();
				for (int j = 0; j < 1; j++) {
					nodeVo.setId(glbdef11[i][j]);
					nodeVo.setName(glbdef11[i][j + 1]);
				}
				childCategoryList.add(nodeVo);
			}
			ListboxUtils.rendererForEdit(bean.getChildtalentname(), childCategoryList);
		}	
		if("技术类".equals(talentCategory)) {
			String[][] glbdef11 = { { "大数据", "大数据" }, { "ICT", "ICT" },
					{ "云计算", "云计算" }, { "业务平台", "业务平台" },
					{ "核心网", "核心网" },{"光传输","光传输"},{"光接入","光接入"},{"IP","IP"},
					{"网络与信息安全","网络与信息安全"},{"卫星","卫星"},{"无线与移动","无线与移动"}, 
					{"电源与基础设施","电源与基础设施"} ,{"终端","终端"},{"IT","IT"},{"综合技术","综合技术"}  };
			for (int i = 0; i < glbdef11.length; i++) {
				NodeVo nodeVo = new NodeVo();
				for (int j = 0; j < 1; j++) {
					nodeVo.setId(glbdef11[i][j]);
					nodeVo.setName(glbdef11[i][j + 1]);
				}
				childCategoryList.add(nodeVo);
			}
			ListboxUtils.rendererForEdit(bean.getChildtalentname(), childCategoryList);
		}	
		if("综合类".equals(talentCategory)) {
			String[][] glbdef11 = { { "战力运营", "战力运营" }, { "人力资源", "人力资源" },
					{ "法律", "法律" }, { "财务管理", "财务管理" },
					{ "党群工会", "党群工会" },{ "风险管理", "风险管理" },
					{ "行政后勤", "行政后勤" }};
			for (int i = 0; i < glbdef11.length; i++) {
				NodeVo nodeVo = new NodeVo();
				for (int j = 0; j < 1; j++) {
					nodeVo.setId(glbdef11[i][j]);
					nodeVo.setName(glbdef11[i][j + 1]);
				}
				childCategoryList.add(nodeVo);
			}
			ListboxUtils.rendererForEdit(bean.getChildtalentname(), childCategoryList);
		}	
		
		
		
			
	}
	/**
	 * 监听人才子标签，带出父标签(产品类)
	 */
	public void onSelect$talentcLabel()  {
		//获取标签
		if(bean.getTalentcLabel().getSelectedItem().getIndex()>0) {
			labelcType="产品类";
		}else {
			labelcType="";
		}
	}
	/**
	 * 监听人才子标签，带出父标签(行业类)
	 */
	public void onSelect$talenthLabel()  {
		//获取标签
		if(bean.getTalenthLabel().getSelectedItem().getIndex()>0) {
			labelhType="行业类";
		}else {
			labelhType="";
		}
	}
	/**
	 * 监听人才子标签，带出父标签(产品类)
	 */
	public void onSelect$talentzLabel()  {
		//获取标签
		if(bean.getTalentzLabel().getSelectedItem().getIndex()>0) {
			labelzType="综合类";
		}else {
			labelzType="";
		}
	}
	/**
	 * 获取全局变量，绑定数据导页面
	 * @Title: binbBean   
	 * @Description: TODO 
	 * @param: @throws InterruptedException      
	 * @return: void      
	 * @throws
	 */
	private void binbBean() throws InterruptedException{
		if (StrUtil.isNullOrEmpty(PlatformUtil.getCurrentUser())) {
			ZkUtil.showError("当前登录用户不存在!", "错误提示");
			return;
		} else {
			String screenName = PlatformUtil.getCurrentUser().getScreenName();
			if("n".equals(screenName.substring(0,1).toLowerCase())) {
				screenName=screenName.substring(1);
			}
			uecStaffAll.setCode(screenName.toUpperCase());
			uecStaffAll = uecStaffAllManager.findUecStaffAll(uecStaffAll);
			logDown.setCode(uecStaffAll.getCode());
		    logDown = logDownManager.findLogDownByLogDown(logDown);
		    if(logDown != null) {
		    	PubUtil.fillBeanFromPo(logDown, bean);
		    }
		}
	}
	
	/**
	 * 保存
	 * 
	 * @throws Exception
	 */
	public void onOk() throws Exception {
		String msg = this.checkUacStaffData();
		if (null != msg) {
			Messagebox.show(msg);
			return;
		}
		if(logDown != null) {
			logDown.setLabelChanPinType(labelcType);
			logDown.setLabelHangYeType(labelhType);
			logDown.setLabelZongHeType(labelzType);
			if(StrUtil.isNullOrEmpty(bean.getTalentcLabel().getSelectedItem().getValue())) {
				logDown.setTalentChanPin((String)bean.getTalentcLabel().getSelectedItem().getValue());
			}
			if(StrUtil.isNullOrEmpty(bean.getTalenthLabel().getSelectedItem().getValue())) {
				logDown.setTalentHangYe((String)bean.getTalenthLabel().getSelectedItem().getValue());
			}
			/*if(StrUtil.isNullOrEmpty(bean.getTalentzLabel().getSelectedItem().getValue())) {
				logDown.setTalentzLabel((String)bean.getTalentzLabel().getSelectedItem().getValue());
			}*/
			logDown.setTalentname((String)bean.getTalentname().getSelectedItem().getValue());
			logDown.setChildtalentname((String)bean.getChildtalentname().getSelectedItem().getValue());
			logDown.setBegindatetanlent(bean.getBegindatetanlent().getValue());
			logDown.setBegindatechild(bean.getBegindatechild().getValue());
			
			logDown.updateOnly();
		}

	}
	/**
	 * 检测填入的参数是否为空
	 */
	private String checkUacStaffData() {
		if (StrUtil.isNullOrEmpty(bean.getTalentname().getSelectedItem().getValue())) {
			return "请选择专家人才类别";
		} else if (StrUtil.isNullOrEmpty(bean.getChildtalentname().getSelectedItem().getValue())) {
			return "请选择子专业";
		} else if (StrUtil.isNullOrEmpty(bean.getBegindatetanlent().getValue())) {
			return "从事此专家类别日期不可为空";
		}  else if (StrUtil.isNullOrEmpty(bean.getBegindatechild().getValue())) {
			return "从事子专业日期不可为空";
		} 
		
		return null;
	}
	
}
